# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>

pkgname=r2ghidra
_gitcommit=345ea97fd25f5108f0e4e3aba52468cb2ae95f64
_ghidra_native=21b6dbafee5b8265ee000827dd31f542ad46861d
pkgver=5.8.8
pkgrel=1
pkgdesc='Deep ghidra decompiler integration for radare2 and iaito'
url='https://github.com/radareorg/r2ghidra'
arch=('loong64' 'x86_64')
license=('LGPL3')
depends=('radare2' 'glibc')
makedepends=('git')
provides=('radare2-r2ghidra')
replaces=('r2ghidra-dec')
source=("git+https://github.com/radareorg/r2ghidra#commit=${_gitcommit}"
        "git+https://github.com/radareorg/ghidra-native.git#commit=${_ghidra_native}"
        git+https://github.com/zeux/pugixml.git)
sha512sums=('SKIP'
            'SKIP'
            'SKIP')

pkgver() {
  cd ${pkgname}
  git describe --tags --match '5*' | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
  cd ${pkgname}
  git submodule init
  git config submodule."third-party/pugixml".url "${srcdir}/pugixml"
  git -c protocol.file.allow=always submodule update --recursive
  ln -sf "${srcdir}/ghidra-native" ghidra-native
}

build() {
  cd ${pkgname}
  make -C ghidra-native patch
  ./configure PREFIX=/usr
  make
}

package() {
  cd ${pkgname}
  make DESTDIR="$pkgdir" install
  r2version=$(r2 -v|grep radare2|sed -E 's/radare2 ([0-9\.]+) .*/\1/')
  ln -s /usr/lib/radare2/${r2version} "${pkgdir}/usr/lib/radare2/last"
}

# vim: ts=2 sw=2 et:
